import request from '@/utils/request'
import type { Role, RoleQuery } from '@/types/api/role'

// 获取角色列表
export function getRoleList(params: RoleQuery) {
  return request<Role[]>({
    url: '/role/list',
    method: 'get',
    params
  })
}

// 添加角色
export function addRole(data: Partial<Role>) {
  return request({
    url: '/role',
    method: 'post',
    data
  })
}

// 更新角色
export function updateRole(data: Partial<Role>) {
  return request({
    url: `/role/${data.id}`,
    method: 'put',
    data
  })
}

// 删除角色
export function deleteRole(id: number) {
  return request({
    url: `/role/${id}`,
    method: 'delete'
  })
}

// 获取角色权限
export function getRolePermissions(roleId: number) {
  return request<number[]>({
    url: `/role/${roleId}/permissions`,
    method: 'get'
  })
}

// 保存角色权限
export function saveRolePermissions(data: { roleId: number; permissionIds: number[] }) {
  return request({
    url: `/role/${data.roleId}/permissions`,
    method: 'put',
    data
  })
} 